<?php

require 'defaultController.php';

class adminController extends defaultController {

    function indexAction() {
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
       
        $this->_view('admin.tpl.php');
    }
    
    function aloginAction(){
        $this->_view('admin_login.tpl.php');
    }
    
    function loginAction(){
        $name=$this->for_post('username');
        $password=$this->for_post('password');
        $result=$this->_model('admin')->checkpassoword($name,$password);  
        if($result){  
            $_SESSION['adminid']=$result['id'];
            $_SESSION['adminname']=$result['username'];
            echo 1;
        }else{
            echo 0;
        }
    }
    
    function addartAction(){  
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
        if(isset($_POST['submit'])){
            $data=array(
                'title' => $this->for_post('title'),
                'artc' => $this->for_post('class'),
                'author' => $this->for_post('author'),
                'content' => $this ->for_post('content'),
                'data'   => date("Y/m/d")
            );        
            $result=$this->_model('art')->addart($data);
            if($result){
                $this->redirectPage("index.php?c=admin&a=artlist");
            }           
        }else{
            $this -> _view('art.tpl.php');
        }
    }
    
    function artlistAction(){
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
            $result=$this->_model('art')->getallart();
            $data['artlist']=$result;
            $this -> _view('artlist.tpl.php',$data);
    }
    
    function updateartAction(){
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
        if(isset($_POST['submit'])){
            $data=array(
                'title' => $this->for_post('title'),
                'artc'=>$this->for_post('class'),
                'author' => $this->for_post('author'),
                'content' => $this ->for_post('content'),
                'data'   => date("Y/m/d")
            );  
            echo $this->for_get('id');
            $result=$this->_model('art')->updateart($data,$this->for_get('id'));
            if($result){
                $this->redirectPage("index.php?c=admin&a=artlist");
            } 
        }else{
            $result=$this->_model('art')->getoneart($this->for_get('id'));
            $data['art']=$result;
            $this -> _view('editart.tpl.php',$data);
        }         
    }
    function delartAction(){
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
        $result=$this->_model('art')->delart($this->for_get('id'));
        if($result){
            $this->redirectPage("index.php?c=admin&a=artlist");
        }
    }
    
    function tasklistAction(){
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
        if($this->for_get('class')){
            $result=$this->_model('task')->alllist2($this->for_get('class'));
        }else{
            $result=$this->_model('task')->alllist();
        }
        $data['list']=$result;
        $this -> _view('admintasklist.tpl.php',$data);
    }
    
    function checktasklistAction(){
        if(!$this->checkadminLogin()){
          $this->redirectPage("index.php?c=admin&a=alogin");
        }
        $status=$this->for_get('class');
        $id=$this->for_get('id');
        $data=array(
            'status'=>$status
        );
        $result=$this->_model('task')->updatestatus($id,$data);
        if($result){
            $this->showMessage("修改成功!");
        }else{
            $this->showMessage("未修改!");
        }
    }
    function backmAction(){
        $data['list']=$this->_model('backmoney')->all2();
         $this -> _view('adminbm.tpl.php',$data);
    }
    
    function backmcheckAction(){
        $id=$this->for_get('id');
        $status=$this->for_get('status');
        $data=array(
            'status'=>$status
        );
        $result=$this->_model('backmoney')->update($data,$id);
        if($result){
             $this->showMessage("修改成功!");
        }else{
            $this->showMessage("修改错误！!");
        }
    }

}
